package fr.kotton.myorganizer.utils.sql;


import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.os.AsyncTask;

import fr.kotton.myorganizer.db.MyOrganizerDbHelper;
import fr.kotton.myorganizer.task.interfaces.TasksQueryCompleteListener;

public class DatabaseRemover extends AsyncTask<SqlReadQuery, Void, Void> {

    private MyOrganizerDbHelper mDbHelper;
    private TasksQueryCompleteListener mCallback;

    public DatabaseRemover(Context pContext, TasksQueryCompleteListener SqlQueryCompleteListener) {
        super();
        mDbHelper = new MyOrganizerDbHelper(pContext);
        mCallback = SqlQueryCompleteListener;
    }

    @Override
    protected Void doInBackground(SqlReadQuery... pSqlReadQueries) {

        SQLiteDatabase lDatabase = mDbHelper.getReadableDatabase();

        SqlReadQuery lSqlReadQuery = pSqlReadQueries[0];

        lDatabase.delete(
                lSqlReadQuery.getTable(),                    // The table to query
                lSqlReadQuery.getSelection(),                                // The columns for the WHERE clause
                lSqlReadQuery.getSelectionArgs()                            // The values for the WHERE clause
        );

        return null;
    }

    @Override
    protected void onPostExecute(Void result) {

        mCallback.onTasksDeleteQueryComplete();
    }
}